package com.vue.controller.teacher;
import com.vue.dto.StudentPageQueryDTO;

import com.vue.entity.Student;
import com.vue.result.PageResult;
import com.vue.result.Result;
import com.vue.service.StudentService;

import com.vue.dto.StudentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/studentManage")
@Slf4j
@Api(tags = "学生管理相关接口")
public class S_ManageController {

    @Autowired
    private StudentService studentService;

    /**
     * 学生分页查询
     * @param studentPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("学生分页查询")
    public Result<PageResult> studentPage(StudentPageQueryDTO studentPageQueryDTO){
        log.info("学生分页查询：{}", studentPageQueryDTO);
        PageResult pageResult = studentService.studentPageQuery(studentPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除学生
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除学生")
    public Result deleteStudent(@PathVariable Long id){
        log.info("根据id删除学生：{}",id);
        studentService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加学生
     * @param studentDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加学生")
    public Result addStudent(@RequestBody StudentDTO studentDTO){
        log.info("添加学生：{}", studentDTO);
        studentService.add(studentDTO);
        return Result.success();
    }

    /**
     * 修改学生
     * @param studentDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改学生")
    public Result update(@RequestBody StudentDTO studentDTO){
        studentService.update(studentDTO);
        return Result.success();
    }
}
